package com.gt.channel;

import com.gt.entity.WxReq;
import com.gt.enums.BatchPoolCallEnum;
import com.gt.utils.SpringContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 许剑峰
 */
@Slf4j
@Service
public class ExchangeService {
    private Map<Class<?>, Object> clientMap = new HashMap<>();

//    @Autowired
//    public ExchangeService(ApplicationContext applicationContext) {
//        // 注入所有 Feign 客户端实例
//        for (BatchPoolCallEnum method : BatchPoolCallEnum.values()) {
//            Class<?> clientClass = method.getClazz();
//            Object client = applicationContext.getBean(clientClass);
//            clientMap.put(clientClass, client);
//        }
//    }
    /**
     * 转发到相应插件回调feign
     *
     * @param callbackCode 回调业务码
     * @param object       返回参数
     * @param type 类型，默认为发券回调，2为核销回调
     * @throws Exception 异常
     */
    public Object callFeignMethod() throws Exception {
        String callbackCode = "WeChatRestServiceImpl";
//        String callbackCode = "InterfaceLogServiceImpl";
        BatchPoolCallEnum batchPoolCallEnum = BatchPoolCallEnum.getByCode(callbackCode);
        WxReq wxReq = new WxReq().setUrl("https://api.mch.weixin.qq.com/v3/marketing/favor/stocks/19686538").setMethod("GET").setBody("");

        Class<?> aClass = SpringContextHolder.getBean(batchPoolCallEnum.getClazz()).getClass();
        Method method = aClass.getMethod(batchPoolCallEnum.getMethod(), WxReq.class);
//        return method.invoke(aClass, wxReq);

        method = aClass.getMethod(batchPoolCallEnum.getMethod(), String.class, String.class, String.class);
        return method.invoke(aClass, "https://api.mch.weixin.qq.com/v3/marketing/favor/stocks/19686538?stock_creator_mchid=1501970731","GET","");
    }
}
